#define DEBUG
#include <cstdio>
#define INF 0xfffffff
#define MAXN 100000
#define MAXK 6

using namespace std;

unsigned int c[MAXK+1][MAXK*2+1];

void initc() {
  c[0][0] = 1;
  for (int i=1; i<=MAXK; i++) {
    c[i][0] = 1;
    for (int j=1; j<=i; j++) {
      c[i][j] = c[i-1][j-1]+c[i-1][j];
    }
  }
}

int min(int a, int b) {
  return a<b ? a : b;
}

int max(int a, int b) {
  return a>b ? a : b;
}

void initF(unsigned int f[MAXK+1]) {
  for (int i=1; i<=MAXK; i++) {
    f[i] = 0;
  }
  f[0] = 1;
}

void cpyF(unsigned int x[MAXK+1], unsigned int y[MAXK+1]) {
  for (int i=0; i<=MAXK; i++) {
    y[i] = x[i];
  }
}

void calcF(unsigned int x[MAXK+1], unsigned int y[MAXK+1], unsigned int z[MAXK+1], int k) {
  z[0] = 1;
  for (int i=1; i<=k; i++) {
    z[i] = 0;
    for (int j=0; j<=i; j++) {
      z[i] += x[j]*y[i-j]*c[i][j];
    }
  }
}

class SegmentTree {
public:
  unsigned int minv[4*MAXN+1][2], f[4*MAXN+1][MAXK+1];

  void merge(int o) {
    if (minv[o*2][0]<minv[o*2+1][0]) {
      minv[o][0] = minv[o*2][0];
      minv[o][1] = minv[o*2][1];
    } else {
      minv[o][0] = minv[o*2+1][0];
      minv[o][1] = minv[o*2+1][1];
    }
    calcF(f[o*2], f[o*2+1], f[o], MAXK);
  }

  void build(int o, int l, int r, int *a) {
    if (l==r) {
      f[o][1] = minv[o][0] = a[l];
      f[o][0] = 1, minv[o][1] = l;
    } else {
      int mid=(l+r)/2;
      build(o*2, l, mid, a);
      build(o*2+1, mid+1, r, a);
      merge(o);
    }
  }

  void get(int o, int l, int r, int tl, int tr, unsigned int tmin[2], unsigned int tsum[MAXK+1], int k) {
    if (tl>tr) {
      return;
    }
    if (l==tl && r==tr) {
      if (tmin[0]>minv[o][0]) {
	tmin[0] = minv[o][0];
	tmin[1] = minv[o][1];
      }
      static unsigned int temp[6];
      cpyF(tsum, temp);
      calcF(temp, f[o], tsum, k);
    } else {
      int mid=(l+r)/2;
      if (tl<=mid && tr>=l) {
	get(o*2, l, mid, max(l, tl), min(mid, tr), tmin, tsum, k);
      }
      if (tl<=r && tr>mid) {
	get(o*2+1, mid+1, r, max(mid+1, tl), min(r, tr), tmin, tsum, k);
      }
    }
  }
};

void qsort(int *d, int *v, int l, int r) {
  int i=l, j=r, mid=d[(l+r)/2], temp;
  for (; i<=j; ) {
    for (; d[j]>mid; j--);
    for (; d[i]<mid; i++);
    if (i<=j) {
      temp=d[i], d[i]=d[j], d[j]=temp;
      temp=v[i], v[i]=v[j], v[j]=temp;
      i++, j--;
    }
  }
  if (i<r) {
    qsort(d, v, i, r);
  }
  if (j>l) {
    qsort(d, v, l, j);
  }
}

int main() {
#ifdef DEBUG
  freopen("1.in", "r", stdin);
  freopen("1.out", "w", stdout);
#endif

  static int d[MAXN+1], v[MAXN+1];
  static SegmentTree sgt;
  initc();
  int n, q;
  scanf("%d %d", &n, &q);
  for (int i=1; i<=n; i++) {
    scanf("%d", d+i);
  }
  for (int i=1; i<=n; i++) {
    scanf("%d", v+i);
  }
  qsort(d, v, 1, n);

  sgt.build(1, 1, n, v);

  for (int i=1; i<=q; i++) {
    int l, r, k;
    scanf("%d %d %d", &l, &r, &k);
    int ansl=1, ansr=n;
    for (int x=1, y=n, mid; x<=y; ) {
      mid=(x+y)/2;
      if (d[mid]>=l) {
	ansl = mid;
	y = mid-1;
      } else {
	x = mid+1;
      }
    }
    for (int x=1, y=n, mid; x<=y; ) {
      mid=(x+y)/2;
      if (d[mid]<=r) {
	ansr = mid;
	x = mid+1;
      } else {
	y = mid-1;
      }
    }
    static unsigned int minv[2], sumv[3][MAXK+1], temp[2];
    minv[0] = INF;
    initF(sumv[0]);
    sgt.get(1, 1, n, ansl, ansr, minv, sumv[0], k);
    unsigned int all=sumv[0][k];
    initF(sumv[1]);
    sgt.get(1, 1, n, ansl, minv[0]-1, temp, sumv[1], k);
    initF(sumv[2]);
    sumv[2][1] = minv[1];
    calcF(sumv[1], sumv[2], sumv[0], k);
    sgt.get(1, 1, n, minv[0]+1, ansr, temp, sumv[1], k);
    calcF(sumv[0], sumv[1], sumv[2], k);
    printf("%u\n", all-sumv[2][k]);
  }

  fcloseall();
  return 0;
}
